#include"goods.h"
#include"mainwindow.h"

#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMessageBox>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("../storemanagement/sql/my.db");
    if(false==db.open())
    {
        QMessageBox::critical(0,"连接失败","无法连接到数据库",QMessageBox::Cancel);
    }
    QSqlQuery query;
    query.exec("pragma foreign_keys=on");
    query.exec("create table category(categoryid integer primary key,name text)");
    query.exec("create table goods(id integer primary key,categoryid int,name varchar,price real,num integer,picture blob,foreign key(categoryid) references category)");
    query.exec("create table order1(OrderID integer primary key,id integer,name text,time text,count integer,price real,flag integer,foreign key(id) references goods)");
    query.exec(QString("insert into category(categoryid,name)values(%1,'%2')").arg(0).arg("test"));
    query.exec(QString("insert into category(categoryid,name)values(%1,'%2')").arg(1).arg("test2"));
    MainWindow w;
    w.show();
    return a.exec();
}
